# encoding: utf-8

import xlrd
import pandas as pd  # 导入模块重命名为pd
import win32com.client
import shutil
import os

class ExcelUtil:
    def __init__(self,filename="",sheet=0):
        if filename != "":
            self.data = xlrd.open_workbook(filename)
            self.table = self.data.sheets()[0]
            self.rows = self.table.nrows

    def close(self):
        self.data.release_resources()
        del self

    def saveas(self,filename):
        shutil.move(filename,os.getcwd()+"\\aa.xlsx")
        xlApp = win32com.client.Dispatch("Excel.Application")
        xlApp.Visible = True
        books = xlApp.Workbooks.Open(os.getcwd()+"\\aa.xlsx")
        # 这里的文件名可以修改为打开的那张表的名字，这种情况就是覆盖原先的表
        books.SaveAs(filename)
        xlApp.Quit()



